package es.aqua.aquac.il.domain;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.PostLoad;
import javax.persistence.Table;
import javax.persistence.Transient;

import es.aqua.aquac.util.Constants;

@Entity
@Table(name = "RECIBOS")
public class Recibo extends BaseDomainObject implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 572632225603495717L;

	/**
	 * Id
	 */
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "RECIBO_ID")
	private Integer id;

	/**
	 * Propietario
	 */
	@ManyToOne
	@JoinColumn(name = "PROPIETARIO_ID", nullable = false)
	private Propietario propietario = new Propietario();

	/**
	 * Facutra
	 */
	@ManyToOne
	@JoinColumn(name = "FACTURA_ID", nullable = false)
	private Factura factura = new Factura();

	/**
	 * Lectura Inicial
	 */
	@Column(name = "LECTURA_INICIAL", nullable = false, precision = Constants.DB_TAM_PRECISION)
	private Double lecturaInicial;

	/**
	 * Lectura Final
	 */
	@Column(name = "LECTURA_FINAL", nullable = false, precision = Constants.DB_TAM_PRECISION)
	private Double lecturaFinal;

	/**
	 * Consumo
	 */
	@Transient
	private Double consumo;

	/**
	 * Importe Residuos Solidos Urbanos
	 */
	@Column(name = "IMPORTE_RSU", nullable = false, precision = Constants.DB_TAM_PRECISION)
	private Double importeRSU;

	/**
	 * Importe Ciclo del Agua
	 */
	@Column(name = "IMPORTE_CUOTA", nullable = false, precision = Constants.DB_TAM_PRECISION)
	private Double importeCuota;

	/**
	 * Importe Ciclo del Agua
	 */
	@Column(name = "IMPORTE_AGUA", nullable = false, precision = Constants.DB_TAM_PRECISION)
	private Double importeAgua;

	/**
	 * Importe Total
	 */
	@Transient
	private Double total;

	/**
	 * @return the id
	 */
	public Integer getId() {
		return id;
	}

	/**
	 * @param id
	 *            the id to set
	 */
	public void setId(Integer id) {
		this.id = id;
	}

	/**
	 * @return the propietario
	 */
	public Propietario getPropietario() {
		return propietario;
	}

	/**
	 * @param propietario
	 *            the propietario to set
	 */
	public void setPropietario(Propietario propietario) {
		this.propietario = propietario;
	}

	/**
	 * @return the factura
	 */
	public Factura getFactura() {
		return factura;
	}

	/**
	 * @param factura
	 *            the factura to set
	 */
	public void setFactura(Factura factura) {
		this.factura = factura;
	}

	/**
	 * @return the lecturaInicial
	 */
	public Double getLecturaInicial() {
		return lecturaInicial;
	}

	/**
	 * @param lecturaInicial
	 *            the lecturaInicial to set
	 */
	public void setLecturaInicial(Double lecturaInicial) {
		this.lecturaInicial = lecturaInicial;
	}

	/**
	 * @return the lecturaFinal
	 */
	public Double getLecturaFinal() {
		return lecturaFinal;
	}

	/**
	 * @param lecturaFinal
	 *            the lecturaFinal to set
	 */
	public void setLecturaFinal(Double lecturaFinal) {
		this.lecturaFinal = lecturaFinal;
	}

	/**
	 * @return the consumo
	 */
	public Double getConsumo() {
		return consumo;
	}

	/**
	 * @param consumo
	 *            the consumo to set
	 */
	public void setConsumo(Double consumo) {
		this.consumo = consumo;
	}

	/**
	 * @return the importeRSU
	 */
	public Double getImporteRSU() {
		return importeRSU;
	}

	/**
	 * @param importeRSU
	 *            the importeRSU to set
	 */
	public void setImporteRSU(Double importeRSU) {
		this.importeRSU = importeRSU;
	}

	/**
	 * @return the importeCuota
	 */
	public Double getImporteCuota() {
		return importeCuota;
	}

	/**
	 * @param importeCuota
	 *            the importeCuota to set
	 */
	public void setImporteCuota(Double importeCuota) {
		this.importeCuota = importeCuota;
	}

	/**
	 * @return the importeAgua
	 */
	public Double getImporteAgua() {
		return importeAgua;
	}

	/**
	 * @param importeAgua
	 *            the importeAgua to set
	 */
	public void setImporteAgua(Double importeAgua) {
		this.importeAgua = importeAgua;
	}

	/**
	 * @return the total
	 */
	public Double getTotal() {
		return total;
	}

	/**
	 * @param total
	 *            the total to set
	 */
	public void setTotal(Double total) {
		this.total = total;
	}

	@PostLoad
	public void total() {

		this.total = this.importeAgua + this.importeCuota + this.importeRSU;

		this.consumo = this.lecturaFinal - this.lecturaInicial;

	}
}
